#include"ChatServer.hpp"
#include"Logger.hpp"
#include"Routine.hpp"
#include"ThreadPool.hpp"
#include<memory>



void Useage_Server(char* ch[])
{
    std::cout << "Useage: " << ch[0] << " port" << std::endl; 
}

int main(int argc,char* argv[])
{
    // EnableScreen();
    // LOG(LogLevel::INFO) << "test ecation" << "\r\n";


    
    if(argc != 2)
    {
        Useage_Server(argv);
        exit(1);
    }
    EnableScreen();
    std::string port = argv[1];
    uint16_t _port = std::stoi(port);
    
    std::unique_ptr<Routine> rt = std::make_unique<Routine>();
    auto it = ThreadPool<task_t>::GetInstance();
    




    std::unique_ptr<ChatServer> _uptr = std::make_unique<ChatServer>(_port,
        [&rt,&it](int _sockfd,const std::string message,Inet_Addr _addr){
            // LOG(LogLevel::DEBUG) << _sockfd << "\r\n";
            // LOG(LogLevel::DEBUG) << _addr.Get() << "\r\n";
            // LOG(LogLevel::DEBUG) << message.c_str() << "\r\n";
            
            task_t task = [&it,&rt,_sockfd,message,_addr](){
                rt->Start(_sockfd,message,_addr);                
            };

            it->push(task);




    });

    _uptr->Init();
    _uptr->Start();
    _uptr->Stop();


    return 0;
}
